<% include ../header.ejs %>

<link rel="stylesheet" href="/lib/datetimepicker/css/amazeui.datetimepicker.css"/>

<script src="/lib/datetimepicker/js/amazeui.datetimepicker.min.js"></script>
<script src="/lib/datetimepicker/js/locales/amazeui.datetimepicker.zh-CN.js"></script>

<style>
    #vld-tooltip {
        position: absolute;
        z-index: 1000;
        padding: 5px 10px;
        background: #F37B1D;
        min-width: 150px;
        color: #fff;
        transition: all 0.15s;
        box-shadow: 0 0 5px rgba(0,0,0,.15);
        display: none;
    }

    #vld-tooltip:before {
        position: absolute;
        top: -8px;
        left: 50%;
        width: 0;
        height: 0;
        margin-left: -8px;
        content: "";
        border-width: 0 8px 8px;
        border-color: transparent transparent #F37B1D;
        border-style: none inset solid;
    }

</style>

<header data-am-widget="header" data-am-sticky class="am-header am-header-default" id="appTemplates-Nav">
    <div class="am-header-left am-header-nav">
        <a href='javascript:history.go(-1)' class="">
            <img class="am-header-icon-custom"
                 src="data:image/svg+xml;charset&#x3D;utf-8,&lt;svg xmlns&#x3D;&quot;http://www.w3.org/2000/svg&quot; viewBox&#x3D;&quot;0 0 12 20&quot;&gt;&lt;path d&#x3D;&quot;M10,0l2,2l-8,8l8,8l-2,2L0,10L10,0z&quot; fill&#x3D;&quot;%23fff&quot;/&gt;&lt;/svg&gt;"
                 alt=""/>
        </a>
    </div>

    <h1 class="am-header-title">
        <a href="#title-link" class="" id="Typeface-whitecolor">申请晨会</a>
    </h1>

    <div class="am-header-right am-header-nav">
        <a onclick="javascript:$('#save').click();" class=""
           data-am-modal="{target: '#modal-type-add', closeViaDimmer: 0, width: 240, height: 260}">保存</a>
    </div>
</header>

<form name="addstockrecommendadd" class="am-form" method="post" action="add" data-am-validator>
    <fieldset>
        <div class="am-form-group" id="dateClass">
            <label for="doc-vld-name">时间:</label>
            <div class="am-input-group am-datepicker-date" data-am-datepicker="{format: 'yyyy-mm-dd'}">
                <input type="text" class="am-form-field" id="date" name="date" placeholder="选择时间" readonly required>
                <span class="am-input-group-btn am-datepicker-add-on">
                <button class="am-btn am-btn-default" type="button"><span class="am-icon-calendar"></span> </button>
              </span>
            </div>
        </div>

        <!---->
        <input type="hidden" name="seller" value="<%= createUser.seller.rowId %>">


        <div class="am-form-group" style="margin-top:5px;">
            <label for="doc-vld-name">发起人:</label>
            <select data-am-selected="{btnWidth: '100%'}" placeholder="请选择发起人" id="analyst" name="analyst" required>
                <% person.obj.forEach(function (data, index) { %>
                <option value="<%= data.rowId %>" <% if(createUser.rowId == data.rowId){ %>selected
                        <% } %>
                ><%= data.name %></option>
                <% }) %>
            </select>
        </div>

        <div class="am-form-group" style="margin-top:5px;">
            <label for="doc-vld-name">行业:</label>
            <select name="industry" data-am-selected="{btnWidth:'100%'}" placeholder="选择行业" required>
                <% industry.obj.forEach(function (data, index) { %>
                <option value="<%= data.rowId %>" <% if(index == 0){ %>selected
                        <% } %>
                ><%= data.industryName %></option>
                <% }) %>
            </select>
        </div>

        <div id="analyst_container" class="am-form-group">
            <div class="am-form-group">
                <label for="doc-vld-name">晨会类型:</label>
                <select name="type" data-am-selected="{btnWidth:'100%'}" placeholder="选择晨会类型" required>
                    <option value="行业点评">行业点评</option>
                    <option value="行业调研">行业调研</option>
                    <option value="行业深度">行业深度</option>
                    <option value="公司点评">公司点评</option>
                    <option value="公司调研">公司调研</option>
                    <option value="公司深度">公司深度</option>
                </select>
            </div>

            <div id="group_containers" class="am-form-group" style="display:none">
                <div class="am-form-group" style="margin-top:5px;height:37px;" id="group_container_1">
                    <div class="am-u-sm-6" style="padding-left: 0rem;padding-right: 0rem">
                        <select id="company_name_analyst_1" class="company-data-ajax-2" style="width: 100%"
                                placeholder="选择股票">
                        </select>
                    </div>
                    <div class="am-u-sm-2" style="padding-left: 0rem;padding-right: 0rem">
                        <select id="operate_analyst_1" data-am-selected="{btnWidth:'100%'}" placeholder="选择">
                            <option value="买入" selected>买入</option>
                            <option value="持有">持有</option>
                            <option value="卖出">卖出</option>
                        </select>
                    </div>
                    <div class="am-u-sm-2 am-u-end" style="padding-left: 1rem;padding-right: 0rem">
                        <button type="button" class="am-btn am-icon-plus am-btn-primary" id="plus_1"></button>
                    </div>
                </div>

                <div class="am-form-group" style="display:none;margin-top:5px;height:37px;" id="group_container_2">
                    <div class="am-u-sm-6" style="padding-left: 0rem;padding-right: 0rem">
                        <select id="company_name_analyst_2" class="company-data-ajax-2" style="width: 100%"
                                placeholder="选择股票">
                        </select>
                    </div>
                    <div class="am-u-sm-2" style="padding-left: 0rem;padding-right: 0rem">
                        <select id="operate_analyst_2" data-am-selected="{btnWidth:'100%'}" placeholder="选择">
                            <option value="买入" selected>买入</option>
                            <option value="持有">持有</option>
                            <option value="卖出">卖出</option>
                        </select>
                    </div>
                    <div class="am-u-sm-2" style="padding-left: 1rem;padding-right: 0rem">
                        <button type="button" class="am-btn am-icon-plus am-btn-primary" id="plus_2"></button>
                    </div>
                    <div class="am-u-sm-2 am-u-end" style="padding-left:1rem;padding-right: 0rem">
                        <button type="button" class="am-btn am-icon-minus am-btn-danger" id="minus_1"></button>
                    </div>
                </div>

                <div class="am-form-group" style="display:none;margin-top:5px;height:37px;" id="group_container_3">
                    <div class="am-u-sm-6" style="padding-left: 0rem;padding-right: 0rem">
                        <select id="company_name_analyst_3" class="company-data-ajax-2" style="width: 100%"
                                placeholder="选择股票">
                        </select>
                    </div>
                    <div class="am-u-sm-2" style="padding-left: 0rem;padding-right: 0rem">
                        <select id="operate_analyst_3" data-am-selected="{btnWidth:'100%'}" placeholder="选择">
                            <option value="买入" selected>买入</option>
                            <option value="持有">持有</option>
                            <option value="卖出">卖出</option>
                        </select>
                    </div>
                    <div class="am-u-sm-2 am-u-end" style="padding-left:1rem;padding-right: 0rem">
                        <button type="button" class="am-btn am-icon-minus am-btn-danger" id="minus_2"></button>
                    </div>
                </div>
            </div>
        </div>

        <div class="am-form-group" style="margin-top:5px;">
            <label for="doc-vld-name">发起人联系方式:</label>
            <input type="text" class="" id="contact" name="contact" placeholder="请输入发起人联系方式"
                   value="<%= createUser.phone %>" required>
        </div>

        <div class="am-form-group" style="margin-top:5px;">
            <label for="doc-vld-name">时间偏好:</label>
            <select name="timePlan" data-am-selected="{btnWidth:'100%'}" placeholder="选择时间偏好" required>
                <option value="08:20-08:30">08:20-08:30</option>
                <option value="08:30-08:40">08:30-08:40</option>
                <option value="08:40-08:50">08:40-08:50</option>
                <option value="08:50-09:00">08:50-09:00</option>
            </select>
        </div>

        <div class="am-form-group" style="margin-top:5px;">
            <label for="doc-vld-name">核心观点:</label>
            <textarea class="" rows="5" id="corePoint" name="corePoint" placeholder="核心观点" required></textarea>
        </div>


        <button class="am-btn am-btn-secondary" type="submit" id="save" style="visibility:hidden">提交</button>

        <input type="hidden" id="persons" value="
        <% person.obj.forEach(function (data, index) { %>
                   <%= data.phone %>,
        <% }) %>
        "/>

    </fieldset>
</form>

<script src="/javascripts/app/morningconference/morningconference_add.js"></script>

<script type="text/javascript">
    function checkOne(date) {
        var morningDate = $("#date");
        var offset = morningDate.offset();
        $.get("/smtool_project/api/morningconference/checkOne",
            {date: date},
            function (data, status) {
                console.log(data)
                if (data.obj.length > 0) {
                    morningDate.val("").focus();
                    $tooltip.text(date+"当天已创建晨会！").show().css({
                        left: offset.left + 10,
                        top: offset.top + morningDate.outerHeight() + 10
                    });;
                } else {
                    morningDate.val(date).removeClass("am-field-error");
                    $("#dateClass").removeClass("am-form-error");
                    $tooltip.hide();
                }
            });
    };
    $(".company-data-ajax-2").select2({
        ajax: {
            url: "../../api/dicStock/getStockList",
            dataType: 'json',
            delay: 250,
            data: function (params) {
                return {
                    name: params.term
                };
            },
            processResults: function (data, params) {
                params.page = params.page || 1;
                var newdata = $.map(data.obj, function (obj) {
                    obj.id = obj.id || obj.rowId; // replace pk with your identifier
                    obj.text = obj.text || obj.stockCode + " " + obj.name;
                    return obj;
                });

                return {
                    results: newdata,
                    pagination: {
                        more: (params.page * 30) < data.total_count
                    }
                };
            },
            cache: true
        },
        escapeMarkup: function (markup) {
            return markup;
        }, // let our custom formatter work
        minimumInputLength: 2
    });
    var $tooltip = $('<div id="vld-tooltip">当天已创建晨会！</div>');
    $(function () {
        $("#analyst").change(function () {
            var index = $("#analyst").find("option:selected").index()
            var persons = $("#persons").val().split(',')
            $("#contact").val(Trim(persons[index])%>)
        });
        //日期变更事件--判断一天只能创建一次晨会
        $(".am-datepicker-date").datepicker()
            .on('changeDate.datepicker.amui', function (event) {
                var newDate = event.date.format("yyyy-MM-dd");
                checkOne(newDate);
            });
        $tooltip.appendTo(document.body);
    });

    function Trim(str) {
        return str.replace(/(^\s*)|(\s*$)/g, "");
    }
</script>

<% include ../footer.ejs %>
